#include #include #include #include using namespace std; #define maxn 10000001 void docfile(int a[], int &n); void ghifile(int a[], int n); void swap(int &a, int &b); int partition (int arr[], int low, int high); void quickSort(int arr[], int low, int high); void bubblesort(int a[], int n); void insertionsort(int a[], int n); void shellsort(int arr[],int n); void pigeonhole(int arr[],int n); void countingsort(int input[],int n); int a[maxn],n; int output[maxn]; // The output will have sorted input array clock_t start, end; double cpu_time_used; int main() { docfile(a,n); //printArray(a,n); //Bubblesort // cout<<"Bubblesort"<<"\n"; // start = clock(); // bubblesort(a,n); // end = clock(); // cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC; // cout<<"Time exec:"<> n; for (int i = 0; i < n; i++) { myfile >> a[i]; //cout << a[i] << " "; } myfile.close(); } else cout << "Unable to open file"; } void ghifile(int a[],int n) { std::ofstream myfile; myfile.open("OUT1.out"); if (myfile.is_open()) { myfile<= left && arr[right] > pivot) right--; if (left >= right) break; swap(arr[left], arr[right]); left++; right--; } swap(arr[left], arr[high]); return left; } void quickSort(int arr[], int low, int high) { if (low < high) { /* pi l? ch? s? noi ph?n t? n?y d? d?ng d?ng v? tr? v? l? ph?n t? chia m?ng l?m 2 m?ng con tr?i & ph?i */ int pi = partition(arr, low, high); // G?i d? quy s?p x?p 2 m?ng con tr?i v? ph?i quickSort(arr, low, pi - 1); quickSort(arr, pi + 1, high); } } void bubblesort(int a[], int n){ for (int i=1;i=i;j--){ if(a[j]=0) && (a[j]>x)){ a[j+1] = a[j]; j--; } a[j+1]=x; } } void shellsort(int arr[],int n){ // Start with a big gap, then reduce the gap for (int gap = n/2; gap > 0; gap /= 2) { // cout<<"\r"<= gap && arr[j - gap] > temp; j -= gap) arr[j] = arr[j - gap]; // put temp (the original a[i]) in its correct location arr[j] = temp; } } } void pigeonhole(int arr[],int n){ // Find minimum and maximum values in arr[] int min = arr[0], max = arr[0]; for (int i = 1; i < n; i++) { if (arr[i] < min) min = arr[i]; if (arr[i] > max) max = arr[i]; } int range = max - min + 1; // Find range // Create an array of vectors. Size of array // range. Each vector represents a hole that // is going to contain matching elements. vector holes[range]; // Traverse through input array and put every // element in its respective hole for (int i = 0; i < n; i++) holes[arr[i] - min].push_back(arr[i]); // Traverse through all holes one by one. For // every hole, take its elements and put in // array. int index = 0; // index in sorted array for (int i = 0; i < range; i++) { vector::iterator it; for (it = holes[i].begin(); it != holes[i].end(); ++it) arr[index++] = *it; } } void countingsort(int input[],int n){ int max = input[0]; int min = input[0]; int i; for(i = 1; i < n; i++) { if(input[i] > max) max = input[i]; // Maximum value in array else if(input[i] < min) min = input[i]; // Minimum value in array } int k = max - min + 1; // Size of count array int count_array[k]; // Create a count_array to store count of each individual input value for(i=0; i